<template>
    <!-- 季度评价 -->
    <div class="e-table billList">
        <div class="top">
            <div class="left" style="margin-left: 10px">
                <div>
                    <el-button
                        size="mini"
                        @click="buttonAdd()"
                        style="background: #7aa818; color: #fff"
                        >新增评价</el-button
                    >
                    <el-button
                        size="mini"
                        @click="button()"
                        style="
                            background: #7aa818;
                            color: #fff;
                            padding-left: 10px;
                        "
                        >分包商年度评价信用表</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div>
                    <el-input
                        placeholder=""
                        v-model="advancedQuery.keyword"
                        @keyup.enter.native="getData"
                    >
                        <i
                            slot="suffix"
                            class="el-icon-search"
                            style="cursor: pointer"
                            @click="getData"
                        ></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        style="
                            background: #2e61d7;
                            color: #fff;
                            margin-left: 5px;
                        "
                        @click="onAdvanceSearch"
                        >高级搜索</el-button
                    >
                </div>
            </div>
        </div>
        <el-table
            border
            ref="table"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            highlight-current-row
            class="table"
            height="0"
            @selection-change="handleSelectionChange"
            @cell-mouse-enter="cellMouseEnter"
            @cell-mouse-leave="cellMouseLeave"
            v-sortTable="{ tableData: tableData, _this: this, ref: 'table' }"
        >
            <el-table-column type="selection" width="50" v-if="isBatch">
            </el-table-column>
            <el-table-column
                label="工程分包商名称"
                fixed="left"
                align="left"
                min-width="200"
            >
                <template slot-scope="scope">
                    <span
                        @click="Examine(scope.row)"
                        style="color: blue; cursor: pointer"
                    >
                        {{ scope.row.subcontractorName }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                prop="creditCode"
                label="统一社会信用代码"
                fixed="left"
                min-width="150"
                show-overflow-tooltip
            >
            </el-table-column>

            <el-table-column
                prop="contractName"
                label="合同名称"
                min-width="150"
                show-overflow-tooltip
                align="left"
            >
            </el-table-column>

            <el-table-column
                prop="evaluateDate"
                label="评价日期"
                width="150"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="evaluateQuarter"
                label="评价季度"
                width="150"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="evaluateOrg"
                label="评价机构"
                width="150"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="parentBody"
                label="上级机构"
                width="150"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="evaluateResult"
                label="评价结论"
                width="150"
                show-overflow-tooltip
                align="left"
            >
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态"
                width="150"
                show-overflow-tooltip
            >
                <template slot-scope="scope">
                    <ToolHistory
                        v-if="scope.row.state === 1"
                        :key="scope.$index"
                        url="/outer/audit/getAuditHistory"
                        :billId="scope.row.id"
                        :billType="6045"
                    >
                        <span v-status="scope.row.state">
                            {{ statusLable(scope.row.state) }}
                        </span>
                    </ToolHistory>
                    <span v-else v-status="scope.row.state">
                        {{ statusLable(scope.row.state) }}
                    </span>
                </template>
            </el-table-column>
        </el-table>
        <ComPagination
            :total="totalCount"
            :pageSize.sync="advancedQuery.limit"
            :currentPage.sync="advancedQuery.page"
            @currentChange="currentChange"
            @sizeChange="sizeChange"
        />
    </div>
</template>
<script>
import ComPagination from '@/components/pagination/pagination.vue'
import { advanceSearch } from '@/utils/common.js'
import { mapMutations } from 'vuex'
import examine from '@/api/OutsourcingartyAdmin/subcontractorAdmin/examine.js'
export default {
    components: {
        ComPagination
    },
    data () {
        return {
            isBatch: false, //是否进入批量操作
            batch: '进入批量管理',
            tableData: [],
            MouseEnterId: 0,
            totalCount: 0, //总页数
            advancedQuery: {
                contractName: '', //合同名称
                creditcode: '', //统一社会信用代码
                endDate: '', //结束时间
                keyword: '', //模糊查询关键字
                limit: 20,
                orgId: '', //单据机构
                outerName: '', //分包商名称
                outerTypes: [], //外包方类型
                page: 1,
                quarter: [], //	评价季度
                startDate: '', //开始时间
                states: [] //单据状态
            }
        }
    },
    created () {
        this.getData()
    },
    computed: {
        // 判断状态
        statusLable () {
            return param => {
                const state = this.$store.state.outsourcer.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        }
    },
    methods: {
        //批量管理
        batchOperation () {
            this.isBatch = !this.isBatch
            if (this.isBatch) {
                this.batch = '退出批量管理'
                this.$refs.table.clearSelection()
            } else {
                this.batch = '进入批量管理'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        //查询分包商列表数据
        getData () {
            this.$Ajax
                .httpPost({
                    url: '/outer/quarter/evaluate/listByEntity',
                    params: this.advancedQuery
                })
                .then(res => {
                    this.totalCount = res.totalCount
                    this.tableData = res.list
                })
        },
        //新增按钮
        buttonAdd () {
            this.$router.push('/quarterEvaluateAdd')
        },
        //分包商年度信用评价表
        button () {
            this.$router.push('/subcontractorcContractCredit')
        },

        handleSelectionChange (val) {
            this.multipleSelection = val
        },
        //点击表格查看
        Examine (row) {
            //点击进入查看页面
            const billid = row.id
            if (row.state === -1 || row.state === 2 || row.state === 5) {
                this.$router.push({
                    path: '/quarterEvaluateExamine',
                    query: { billid }
                })
            } else {
                // 根据按钮状态来判断点击编辑进什么页面
                examine
                    .getCurrentUnitInfo({
                        billId: billid,
                        billType: 6045,
                        freeNextUnitIndex: 0,
                        freeNextUser: '',
                        isPass: true,
                        isShareInAudit: true,
                        opinion: ''
                    })
                    .then(res => {
                        this.auditState = res
                        if (this.auditState.canModify) {
                            this.$router.push({
                                path: '/quarterEvaluateEdit',
                                query: { billid }
                            })
                        } else {
                            this.$router.push({
                                path: '/quarterEvaluateExamine',
                                query: { billid }
                            })
                        }
                    })
            }
        },
        //翻页
        currentChange () {
            this.getData()
        },
        //改变条数
        sizeChange () {
            this.getData()
        },
        ...mapMutations(['setSelectedInfo']),
        //高级查询
        onAdvanceSearch () {
            advanceSearch('/quarterEvaluateSearch?type=1').then(res => {
                this.advancedQuery.outerTypes = res.subcontractorTypeKey //分包商id
                this.advancedQuery.states = res.stateTypeKey //状态
                this.advancedQuery.quarter = res.quarter //评价季度
                this.advancedQuery.outerName = res.outerName //分包商名称
                this.advancedQuery.manageOrg = res.manageOrg //管理单位
                this.advancedQuery.contractName = res.contractName //合同名称
                this.advancedQuery.creditcode = res.creditcode //统一社会信用代码
                this.advancedQuery.startDate = res.startDate //开始时间
                this.advancedQuery.endDate = res.endDate //结束时间
                this.getData()
            })
        }
    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
}
</style>
